package com.website.view
{
    import com.greensock.*;
    import com.website.control.PathManager;
    import com.website.event.ClickCloseEvent;
    import com.website.util.Constant;
    
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    public class ContainerShell extends Sprite
    {
        public var shellArray:Array;
		
//        public var locaitonShell:LocationShell;
//        public var awardsShell:AwardsShell;
//        public var typeShell:TypeShell;
//        public var dateShell:DateShell;
//        public var generalInfoShell:GeneralInfoShell;
//        public var projectIconShell:ProjectIconShell;
//        public var iconShell:IconShell;
//        public var partnerShell:PartnerShell;
//        public var triColShell:TriColShell;
//        public var searchShell:SearchShell;
//        public var nameShell:NameShell;
//        public var jobsIndexShell:JobsIndexShell;
//        public var homeShell:HomeShell;
//        public var recentShell:RecentShell;
//        public var projectShell:ProjectShell;
//        public var projVideoShell:ProjVideoShell;
//        public var visualShell:VisualShell;
//        public var pracContainerShell:PracContainerShell;
//		
//        public var bookmarksClear:BookmarksClear;
//        public var bookmarksSend:BookmarksSend;
//        public var bookmarksNew:BookmarksNew;
//        public var bookmarksHelp:BookmarksHelp;
//        public var bookmarksBrowse:BookmarksBrowse;
		
        var currShell:String;
        var incomingXML:XMLList;
        var subPos:int;
        var subNavId:int;
        var projId:int;
        var currCaption:String;
        var navId:int;
        var prevShell:String;
        var coverSprite:Object;
        var indexPoint:Object;
        var currFLV:String;

        public function ContainerShell() : void
        {
            shellArray = new Array();
//            Constant.stage.addEventListener(Event.RESIZE, onResizer);
            doResize();
            return;
        }

        public function newVideoContainer(param1:int, param2:String, param3:String) : void
        {
            prevShell = currShell;
            currShell = "projVideoShell";
            currFLV = param2;
            currCaption = param3;
            projId = param1;
            if (numChildren > 0)
            {
                TweenMax.to(getChildAt(0), Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:removeShell});
            }
            else
            {
                addShell();
            }
            return;
        }

        public function updateProjectNav(param1:int) : void
        {
            if (currShell == "projectShell")
            {
                shellArray[0].switchShells(param1);
            }
            return;
        }

        function removeShell() : void
        {
            if (prevShell == "projVideoShell")
            {
                shellArray[0].deepLinkClose();
            }
            removeChild(getChildAt(0));
            shellArray[0] = null;
            addShell();
            return;
        }

        function doResize() : void
        {
            if (shellArray[0] != undefined)
            {
                if (currShell != "homeShell" && currShell != "projectShell" && currShell != "pracContainerShell" && currShell != "projVideoShell" && currShell != "jobsIndexShell" && currShell != "jobShell" && currShell != "searchShell" && currShell != "bookmarksBrowse" && currShell != "bookmarksSend" && currShell != "bookmarksClear" && currShell != "bookmarksNew" && currShell != "bookmarksHelp")
                {
                    shellArray[0].x = Constant.gridX;
                    shellArray[0].y = Math.round(-2 * Constant.unitW / 75 + (Constant.gridY + Constant.headerH + 2 * (Constant.unitH + Constant.gutterH)));
                }
                else
                {
                    shellArray[0].x = Constant.gridX;
                    shellArray[0].y = Math.round(Constant.gridY);
                }
            }
            return;
        }

        public function fadeOut() : void
        {
            TweenMax.to(this, Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:function ()
            {
                this.visible = false;
                return;
            }
            });
            return;
        }

        public function updateProjectSubNav(param1:int, param2:int) : void
        {
            if (currShell == "projectShell")
            {
                shellArray[0].switchChildShells(param1, param2, true);
            }
            return;
        }

        public function newShell(param1:String, param2:XMLList, param3) : void
        {
            prevShell = currShell;
            currShell = param1;
            incomingXML = param2;
            indexPoint = param3;
            if (numChildren > 0)
            {
                if (prevShell == "nameShell" || prevShell == "typeShell" || prevShell == "locationShell" || prevShell == "dateShell")
                {
                    shellArray[0].removeListeners();
                }
                if ((prevShell == "nameShell" || prevShell == "typeShell" || prevShell == "locationShell" || prevShell == "dateShell") && (currShell == "nameShell" || currShell == "typeShell" || currShell == "locationShell" || currShell == "dateShell"))
                {
                    removeFilterShell();
                }
                else if ((prevShell == "bookmarksBrowse" || prevShell == "bookmarksSend" || prevShell == "bookmarksClear" || prevShell == "bookmarksNew" || prevShell == "bookmarksHelp") && (currShell == "bookmarksBrowse" || currShell == "bookmarksSend" || currShell == "bookmarksClear" || currShell == "bookmarksNew" || currShell == "bookmarksHelp"))
                {
                    removeBookmarkShell();
                }
                else
                {
                    getChildAt(0).blendMode = "layer";
                    TweenMax.to(getChildAt(0), Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:removeShell});
                }
            }
            else
            {
                addShell();
            }
            return;
        }

        public function newProject(param1:int, param2:int) : void
        {
            prevShell = currShell;
            currShell = "projectShell";
            projId = param1;
            navId = param2;
            subPos = 0;
            subNavId = 0;
            if (numChildren > 0)
            {
                TweenMax.to(getChildAt(0), Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:removeShell});
            }
            else
            {
                addShell();
            }
            return;
        }

        public function newSearch() : void
        {
            prevShell = currShell;
            currShell = "searchShell";
            if (numChildren > 0)
            {
                TweenMax.to(getChildAt(0), Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:removeShell});
            }
            else
            {
                addShell();
            }
            return;
        }

        function closeClick(event:ClickCloseEvent) : void
        {
            var e:* = event;
            TweenMax.to(getChildAt(0), Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:function ()
            {
                removeChild(getChildAt(0));
                shellArray[0] = null;
                PathManager.updateAddress("/" + "practice" + "/" + "press" + "/" + "video" + "/" + PathManager.pathNames[3] + "/");
                return;
            }
            });
            return;
        }

        function addShell() : void
        {
            switch(currShell)
            {
                case "homeShell":
                {
//                    shellArray[0] = new HomeShell(myRoot, Constant.fadeSpeed, incomingXML);
                    break;
                }
                case "projectShell":
                {
//                    shellArray[0] = new ProjectShell(myRoot, Constant.fadeSpeed, projId, navId, subNavId, subPos);
                    break;
                }
                case "nameShell":
                {
//                    shellArray[0] = new NameShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "iconShell":
                {
//                    shellArray[0] = new IconShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "projectIconShell":
                {
//                    shellArray[0] = new ProjectIconShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "visualShell":
                {
//                    shellArray[0] = new VisualShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "typeShell":
                {
//                    shellArray[0] = new TypeShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "dateShell":
                {
//                    shellArray[0] = new DateShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "locationShell":
                {
//                    shellArray[0] = new LocationShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "partnerShell":
                {
//                    shellArray[0] = new PartnerShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "staffShell":
                {
//                    shellArray[0] = new PartnerShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "pracContainerShell":
                {
//                    shellArray[0] = new PracContainerShell(myRoot, Constant.fadeSpeed, projId, navId);
                    break;
                }
                case "triColShell":
                {
//                    shellArray[0] = new TriColShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "awardsShell":
                {
//                    shellArray[0] = new AwardsShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "recentShell":
                {
//                    shellArray[0] = new RecentShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "projVideoShell":
                {
//                    shellArray[0] = new ProjVideoShell(myRoot, Constant.fadeSpeed);
//                    shellArray[0].addEventListener(ClickCloseEvent.CLICK_CLOSE, closeClick, false, 0, true);
//                    setTimeout(shellArray[0].loadVideo, Constant.fadeSpeed * 1000, currFLV, currCaption);
                    break;
                }
                case "jobsIndexShell":
                {
//                    shellArray[0] = new JobsIndexShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "jobShell":
                {
//                    shellArray[0] = new JobShell(myRoot, Constant.fadeSpeed, projId);
                    break;
                }
                case "generalInfoShell":
                {
//                    shellArray[0] = new GeneralInfoShell(myRoot, Constant.fadeSpeed, incomingXML);
                    break;
                }
                case "newsShell":
                {
//                    shellArray[0] = new RecentShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "searchShell":
                {
//                    shellArray[0] = new SearchShell(myRoot, Constant.fadeSpeed);
                    break;
                }
                case "bookmarksBrowse":
                {
//                    shellArray[0] = new BookmarksBrowse(myRoot, Constant.fadeSpeed);
                    break;
                }
                case "bookmarksSend":
                {
//                    shellArray[0] = new BookmarksSend(myRoot, Constant.fadeSpeed);
                    break;
                }
                case "bookmarksClear":
                {
//                    shellArray[0] = new BookmarksClear(myRoot, Constant.fadeSpeed);
                    break;
                }
                case "bookmarksNew":
                {
//                    shellArray[0] = new BookmarksNew(myRoot, Constant.fadeSpeed);
                    break;
                }
                case "bookmarksHelp":
                {
//                    shellArray[0] = new BookmarksHelp(myRoot, Constant.fadeSpeed);
                    break;
                }
                default:
                {
                    break;
                }
            }
            shellArray[0].alpha = 0;
            addChild(shellArray[0]);
            doResize();
            shellArray[0].visible = true;
            TweenMax.to(shellArray[0], Constant.fadeSpeed, {alpha:1, overwrite:true});
            return;
        }

        function removeFilterShell() : void
        {
            shellArray[0].coverSprite.visible = true;
            TweenMax.to(shellArray[0].hoverImage, Constant.fadeSpeed, {alpha:0, overwrite:true});
            TweenMax.to(shellArray[0].coverSprite, Constant.fadeSpeed, {alpha:1, overwrite:true, onComplete:function ()
            {
                removeChild(getChildAt(0));
                shellArray[0] = null;
                addFilterShell();
                return;
            }
            });
            return;
        }

        public function newPracContainer(param1:int, param2:int) : void
        {
            prevShell = currShell;
            currShell = "pracContainerShell";
            projId = param1;
            navId = param2;
            if (numChildren > 0)
            {
                TweenMax.to(getChildAt(0), Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:removeShell});
            }
            else
            {
                addShell();
            }
            return;
        }

        public function newJobShell(param1:int) : void
        {
            prevShell = currShell;
            currShell = "jobShell";
            projId = param1;
            if (numChildren > 0)
            {
                TweenMax.to(getChildAt(0), Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:removeShell});
            }
            else
            {
                addShell();
            }
            return;
        }

        function removeBookmarkShell() : void
        {
            shellArray[0].coverSprite.visible = true;
            TweenMax.to(shellArray[0].coverSprite, Constant.fadeSpeed, {alpha:1, overwrite:true, onComplete:function ()
            {
                removeChild(getChildAt(0));
                shellArray[0] = null;
                addBookmarkShell();
                return;
            }
            });
            return;
        }

        function addFilterShell() : void
        {
            switch(currShell)
            {
                case "nameShell":
                {
//                    shellArray[0] = new NameShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "typeShell":
                {
//                    shellArray[0] = new TypeShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "dateShell":
                {
//                    shellArray[0] = new DateShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                case "locationShell":
                {
//                    shellArray[0] = new LocationShell(myRoot, Constant.fadeSpeed, incomingXML, indexPoint);
                    break;
                }
                default:
                {
                    break;
                }
            }
            shellArray[0].alpha = 1;
            shellArray[0].coverSprite.visible = true;
            shellArray[0].coverSprite.alpha = 1;
            addChild(shellArray[0]);
            doResize();
            shellArray[0].visible = true;
            TweenMax.to(shellArray[0].coverSprite, Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:function ()
            {
                shellArray[0].coverSprite.visible = false;
                return;
            }
            });
            return;
        }

        public function newSubProject(param1:int, param2:int, param3:int, param4:int) : void
        {
            prevShell = currShell;
            currShell = "projectShell";
            projId = param1;
            subPos = param2;
            subNavId = param3;
            navId = param4;
            if (numChildren > 0)
            {
                TweenMax.to(getChildAt(0), Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:removeShell});
            }
            else
            {
                addShell();
            }
            return;
        }

        public function updatePracticeNav(param1:int) : void
        {
            if (currShell == "pracContainerShell")
            {
                shellArray[0].switchShells(param1);
            }
            return;
        }

        function onResizer(event:Event) : void
        {
            doResize();
            return;
        }

        function addBookmarkShell() : void
        {
            switch(currShell)
            {
                case "bookmarksBrowse":
                {
//                    shellArray[0] = new BookmarksBrowse(myRoot, Constant.fadeSpeed);
                    break;
                }
                case "bookmarksSend":
                {
//                    shellArray[0] = new BookmarksSend(myRoot, Constant.fadeSpeed);
                    break;
                }
                case "bookmarksClear":
                {
//                    shellArray[0] = new BookmarksClear(myRoot, Constant.fadeSpeed);
                    break;
                }
                case "bookmarksNew":
                {
//                    shellArray[0] = new BookmarksNew(myRoot, Constant.fadeSpeed);
                    break;
                }
                case "bookmarksHelp":
                {
//                    shellArray[0] = new BookmarksHelp(myRoot, Constant.fadeSpeed);
                    break;
                }
                default:
                {
                    break;
                }
            }
            shellArray[0].alpha = 1;
            shellArray[0].coverSprite.visible = true;
            shellArray[0].coverSprite.alpha = 1;
            addChild(shellArray[0]);
            doResize();
            shellArray[0].visible = true;
            TweenMax.to(shellArray[0].coverSprite, Constant.fadeSpeed, {alpha:0, overwrite:true, onComplete:function ()
            {
                shellArray[0].coverSprite.visible = false;
                return;
            }
            });
            return;
        }

    }
}
